// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.Security
{
	public sealed partial class GrantApiKey
	{
		[JsonInclude]
		[JsonPropertyName("expiration")]
		public Elastic.Clients.Elasticsearch.Duration? Expiration { get; set; }

		[JsonInclude]
		[JsonPropertyName("name")]
		public Elastic.Clients.Elasticsearch.Name Name { get; set; }

		[JsonInclude]
		[JsonPropertyName("role_descriptors")]
		public IEnumerable<Dictionary<string, object>>? RoleDescriptors { get; set; }
	}

	public sealed partial class GrantApiKeyDescriptor : SerializableDescriptorBase<GrantApiKeyDescriptor>
	{
		internal GrantApiKeyDescriptor(Action<GrantApiKeyDescriptor> configure) => configure.Invoke(this);
		public GrantApiKeyDescriptor() : base()
		{
		}

		private Elastic.Clients.Elasticsearch.Duration? ExpirationValue { get; set; }

		private Elastic.Clients.Elasticsearch.Name NameValue { get; set; }

		private IEnumerable<Dictionary<string, object>>? RoleDescriptorsValue { get; set; }

		public GrantApiKeyDescriptor Expiration(Elastic.Clients.Elasticsearch.Duration? expiration)
		{
			ExpirationValue = expiration;
			return Self;
		}

		public GrantApiKeyDescriptor Name(Elastic.Clients.Elasticsearch.Name name)
		{
			NameValue = name;
			return Self;
		}

		public GrantApiKeyDescriptor RoleDescriptors(IEnumerable<Dictionary<string, object>>? roleDescriptors)
		{
			RoleDescriptorsValue = roleDescriptors;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (ExpirationValue is not null)
			{
				writer.WritePropertyName("expiration");
				JsonSerializer.Serialize(writer, ExpirationValue, options);
			}

			writer.WritePropertyName("name");
			JsonSerializer.Serialize(writer, NameValue, options);
			if (RoleDescriptorsValue is not null)
			{
				writer.WritePropertyName("role_descriptors");
				JsonSerializer.Serialize(writer, RoleDescriptorsValue, options);
			}

			writer.WriteEndObject();
		}
	}
}